package datatableaux.rules;

import java.util.HashSet;

import datatableaux.*;
import entities.Individual;
import entities.concept.*;

public class DataAndRule {

	DataCompletion dc;
	AndConcept nextExp;
	DataBranching br;

	public DataAndRule(DataCompletion dc) {
		super();
		this.dc = dc;
		this.br = this.dc.getCurrentBranching();
	}
	
	public boolean isApplicable(Individual n){
		HashSet<Concept> unexp = new HashSet<Concept> ();
		unexp.addAll(n.getLabels());
		unexp.removeAll(n.getExpandedLabels());
		if(unexp.size()<1){
			return false;
		}
		for(Concept c : unexp){
			if(c instanceof AndConcept){
				AndConcept ac = (AndConcept) c;
				if(!n.getLabels().containsAll(ac.getConceptSet())){
					this.nextExp = ac;
					return true;
				}
			}
		}
		return false;
	}
	
	public boolean applyRule(Individual n){
		boolean suc = false;
		HashSet<Concept> addc =this.nextExp.getConceptSet();
		n.addLabels(addc);
		n.addExpandedLabels(this.nextExp);
		if(DataBranchChanges.getRecordingStatus()){
			br.getBranchChanges().addToLabel(n, addc);
			br.getBranchChanges().addToExpandedLabel(n, this.nextExp);
			suc = true;
		}
		return suc;
	}
	
	
	
}
